package com.jijuxie.framework.security;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jijuxie.system.service.ISysRoleService;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;

/**
 * 自定义权限验证接口扩展
 */
@Component
public class StpInterfaceImpl implements StpInterface {
    
    private static final Logger log = LoggerFactory.getLogger(StpInterfaceImpl.class);
    
    @Autowired
    private ISysRoleService roleService;

    /**
     * 返回指定账号id所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 暂时返回空集合，权限暂未实现
        return new ArrayList<>();
    }

    /**
     * 返回指定账号id所拥有的角色标识集合
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        if (loginId == null) {
            return new ArrayList<>();
        }
        
        try {
            // 直接从数据库查询角色
            Long userId = Long.valueOf(loginId.toString());
            List<String> roles = roleService.selectRolesByUserId(userId);
            
            // 输出调试信息
            log.info("用户角色列表: userId={}, roles={}", userId, roles);
            
            return roles;
        } catch (Exception e) {
            log.error("获取用户角色失败: {}", e.getMessage());
            return new ArrayList<>();
        }
    }
} 